import Vue from 'vue'
import VueRouter from 'vue-router'

import Foo from '../components/foo.vue'
import Bar from '../components/bar.vue'
import Login from '../components/login.vue'

Vue.use(VueRouter)

const routes = [
  { path: '/foo', component: Foo },
  { path: '/bar', component: Bar },
  { path: '/login', component: Login }
]

const router = new VueRouter({
  routes: routes
})

router.beforeEach((to, from, next) => {
  console.log(to.path)
  if (to.path === '/foo') {
    next({ path: '/login' })
  } else {
    next()
  }
})

export default router
